# -*- coding: utf-8 -*-
"""

相关数值指标计算
    def error_SA(); 绝对误差和
    def error_MSE(); 平均绝对误差
    
"""

import numpy as np


def error_S(a: np.ndarray) -> float:
    """绝对和:

    Args:
        a: numpy ndarray; 变量矩阵

    Returns:
        float;绝对和
    """
    return np.sum(np.abs(a))


def error_SA(a: np.ndarray, b: np.ndarray) -> float:
    """绝对误差和:

    Args:
        a: numpy ndarray; 变量矩阵
        b: numpy ndarray; 变量矩阵

    Returns:
        float;绝对误差和
    """
    return np.sum(np.abs(a - b))/np.sum(np.abs(a))


def error_MSE(a: np.ndarray, b: np.ndarray) -> float:
    """平均绝对误差:

    Args:
        a: numpy ndarray; 变量矩阵
        b: numpy ndarray; 变量矩阵

    Returns:
        float; mse结果
    """
    return np.mean(np.abs(a - b))


# class cal_movingAverage:
#     """
#     滑动平均
#     """

#     def __init__(self, window_size, enabled=False):
#         """
#         Args:
#             window_size: int，窗口大小
#             enabled: bool, 是否执行滑动平均
#         """
#         self.enabled = enabled
#         self.window_size = window_size
#         self.count = 0

#     def update(self, new_value):
#         """
#         根据设置的参数进行滑动平均计算
#         Args:
#             new_value: np, array

#         Returns:

#         """
#         if self.enabled:
#             self.count += 1
#             if self.count == 1:
#                 self.data = new_value
#                 current_average = self.data
#             elif self.count > 1:
#                 self.data = np.vstack([self.data, new_value])
#                 if len(self.data) > self.window_size:
#                     self.data = self.data[1:]
#                 current_average = np.mean(self.data, axis=0)
#         else:
#             return new_value
#         return current_average
